/**
 * Copyright (c) 2014-2017, huli.com
 * All rights reserved.
 */
package com.xiaohujr.xuexue.vm.exceptions;

import java.util.ArrayList;
import java.util.List;

/**
 * 运行时常量池导致的内存溢出异常，在jdk1.6可报错,1.7+无法复现.
 *
 * @author Xue Xue (xuexue1@huli.com)
 * @version $Id$
 * @since 2018/5/3
 */
public class RuntimeConstantPoolOOM {
    /**
     * VM Args: -XX:PermSize=10M -XX:MaxPermSize=10M
     * jdk1.7去永久代,你会发现上述参数：support was removed in 8.0，且程序一直执行不会报错.
     *
     * @param args 参数.
     */
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        int i = 0;
        while (true) {
            list.add(String.valueOf(i++).intern());
        }
    }

//    public static void main(String[] args) {
//        String str1 = new StringBuilder("aaaa").append("bbbb").toString();
//        System.out.print(str1.intern() == str1);
//
//        String str2 = new StringBuilder("ja").append("va").toString();
//        System.out.print(str2.intern() == str2);
//    }

}
